#include<iostream>
#include<stdio.h>
#include<unistd.h>
#include<string>
#include<sys/wait.h>
using namespace std;

int main()
{
    int pipefd[2];
    //0：读端 1：写端
    pipe(pipefd);
    int ret = fork();
    if(ret < 0){
        perror("frok");
        return 0;
    }else if(ret == 0){
        char buf[1024] = {0};
        read(pipefd[0], buf, sizeof(buf) - 1);
        cout<<"i am child, i read : "<<buf<<endl;
    }else{
        string s = "hello bro";
        write(pipefd[1], s.c_str(), s.size());
        wait(NULL);
    }
    return 0;
}
